package cn.com.dcsgo.thread.pool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;

import cn.com.dcsgo.thread.MyCallable;

/**
 * 创建一个定长的线程池，可以设定任务执行的延迟时间，周期性执行任务
 * 适用于线程周期性执行任务的场景
 */
public class ScheduledThreadPoolDemo {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledService = Executors.newScheduledThreadPool(3);
        Future<String> future = scheduledService.submit(new MyCallable());
        try {
            System.out.println(future.get());
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }
}
